#pragma once
#include<iostream>
#include<pthread.h>
#include"Mutex.hpp"

//封装条件变量
class Cond
{
public:
    Cond()
    {
        pthread_cond_init(&_cond,nullptr);
    }
    void Wait(Mutex &lock)
    {
        //条件变量下等待,要解锁
        int n =pthread_cond_wait(&_cond,lock.Get());
        (void)n;

    }
    void NotifyOne()
    {
        //通知一个线程
        int n = pthread_cond_signal(&_cond);
        (void)n;
    }
    void NotifyAll()
    {
        //通知全部线程
        int n = pthread_cond_broadcast(&_cond);
        (void)n;
    }
    ~Cond()
    {
        pthread_cond_destroy(&_cond);
    }
private:
    //自己是条件变量，就要封装条件变量
    pthread_cond_t _cond;
};